//
//  discoverTitleModel.m
//  Focus
//
//  Created by xwc on 14-10-31.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "discoverTitleModel.h"

@implementation discoverTitleModel

- (id)initWithDictionary:(NSMutableArray *)articlesArr pagesArr:(NSMutableArray *)pagesArr pagesNumber:(int)pageNumber
{
    self = [super init];
    if (self) {
        
        //顶层图片
        self.topImageStr = [[pagesArr[pageNumber] objectForKey:@"diy"] objectForKey:@"bgimage_url"];
        
        //大图片+标题
        NSArray *arr = [[pagesArr[pageNumber] objectForKey:@"articles"] componentsSeparatedByString:@","];
        
        if (arr.count == 1) {
            for (int i = 0; i < [articlesArr count]; i++) {
                if ([arr[0] isEqualToString:[articlesArr[i] objectForKey:@"pk"]]) {
                    self.titleImageStr = [[[articlesArr[i] objectForKey:@"media"] lastObject] objectForKey:@"url"];
                    self.imageTitleStr = [articlesArr[i] objectForKey:@"title"];
                    self.weburl0 = [articlesArr[i] objectForKey:@"weburl"];
                    self.pk0 = [articlesArr[i] objectForKey:@"pk"];
                }
            }
        } else if (arr.count == 2) {
            for (int i = 0; i < [articlesArr count]; i++) {
                if ([arr[0] isEqualToString:[articlesArr[i] objectForKey:@"pk"]]) {
                    self.titleImageStr = [[[articlesArr[i] objectForKey:@"media"] lastObject] objectForKey:@"url"];
                    self.imageTitleStr = [articlesArr[i] objectForKey:@"title"];
                    self.weburl0 = [articlesArr[i] objectForKey:@"weburl"];
                    self.pk0 = [articlesArr[i] objectForKey:@"pk"];
                }
            }
            //第一个新闻框
            for (int i = 0; i < [articlesArr count]; i++) {
                if ([arr[1] isEqualToString:[articlesArr[i] objectForKey:@"pk"]]) {
                    self.titleStr1 = [articlesArr[i] objectForKey:@"title"];
                    self.fromStr1 = [articlesArr[i] objectForKey:@"auther_name"];
                    self.weburl1 = [articlesArr[i] objectForKey:@"weburl"];
                    self.pk1 = [articlesArr[i] objectForKey:@"pk"];
                }
            }
        } else if (arr.count == 3){
            for (int i = 0; i < [articlesArr count]; i++) {
                if ([arr[0] isEqualToString:[articlesArr[i] objectForKey:@"pk"]]) {
                    self.titleImageStr = [[[articlesArr[i] objectForKey:@"media"] lastObject] objectForKey:@"url"];
                    self.imageTitleStr = [articlesArr[i] objectForKey:@"title"];
                    self.weburl0 = [articlesArr[i] objectForKey:@"weburl"];
                    self.pk0 = [articlesArr[i] objectForKey:@"pk"];
                }
            }
            //第一个新闻框
            for (int i = 0; i < [articlesArr count]; i++) {
                if ([arr[1] isEqualToString:[articlesArr[i] objectForKey:@"pk"]]) {
                    self.titleStr1 = [articlesArr[i] objectForKey:@"title"];
                    self.fromStr1 = [articlesArr[i] objectForKey:@"auther_name"];
                    self.weburl1 = [articlesArr[i] objectForKey:@"weburl"];
                    self.pk1 = [articlesArr[i] objectForKey:@"pk"];
                }
            }
            //第二个新闻框
            for (int i = 0; i < [articlesArr count]; i++) {
                if ([arr[2] isEqualToString:[articlesArr[i] objectForKey:@"pk"]]) {
                    self.titleStr2 = [articlesArr[i] objectForKey:@"title"];
                    self.fromStr2 = [articlesArr[i] objectForKey:@"auther_name"];
                    self.weburl2 = [articlesArr[i] objectForKey:@"weburl"];
                    self.pk2 = [articlesArr[i] objectForKey:@"pk"];
                }
            }
        } else if (arr.count == 4){
            for (int i = 0; i < [articlesArr count]; i++) {
                if ([arr[0] isEqualToString:[articlesArr[i] objectForKey:@"pk"]]) {
                    self.titleImageStr = [[[articlesArr[i] objectForKey:@"media"] lastObject] objectForKey:@"url"];
                    self.imageTitleStr = [articlesArr[i] objectForKey:@"title"];
                    self.weburl0 = [articlesArr[i] objectForKey:@"weburl"];
                    self.pk0 = [articlesArr[i] objectForKey:@"pk"];
                }
            }
            //第一个新闻框
            for (int i = 0; i < [articlesArr count]; i++) {
                if ([arr[1] isEqualToString:[articlesArr[i] objectForKey:@"pk"]]) {
                    self.titleStr1 = [articlesArr[i] objectForKey:@"title"];
                    self.fromStr1 = [articlesArr[i] objectForKey:@"auther_name"];
                    self.weburl1 = [articlesArr[i] objectForKey:@"weburl"];
                    self.pk1 = [articlesArr[i] objectForKey:@"pk"];
                }
            }
            //第二个新闻框
            for (int i = 0; i < [articlesArr count]; i++) {
                if ([arr[2] isEqualToString:[articlesArr[i] objectForKey:@"pk"]]) {
                    self.titleStr2 = [articlesArr[i] objectForKey:@"title"];
                    self.fromStr2 = [articlesArr[i] objectForKey:@"auther_name"];
                    self.weburl2 = [articlesArr[i] objectForKey:@"weburl"];
                    self.pk2 = [articlesArr[i] objectForKey:@"pk"];
                }
            }
            //第三个新闻框
            for (int i = 0; i < [articlesArr count]; i++) {
                if ([arr[3] isEqualToString:[articlesArr[i] objectForKey:@"pk"]]) {
                    self.titleStr3 = [articlesArr[i] objectForKey:@"title"];
                    self.fromStr3 = [articlesArr[i] objectForKey:@"auther_name"];
                    self.weburl3 = [articlesArr[i] objectForKey:@"weburl"];
                    self.pk3 = [articlesArr[i] objectForKey:@"pk"];
                }
            }
        } else if (arr.count == 5) {
            for (int i = 0; i < [articlesArr count]; i++) {
                if ([arr[0] isEqualToString:[articlesArr[i] objectForKey:@"pk"]]) {
                    self.titleImageStr = [[[articlesArr[i] objectForKey:@"media"] lastObject] objectForKey:@"url"];
                    self.imageTitleStr = [articlesArr[i] objectForKey:@"title"];
                    self.weburl0 = [articlesArr[i] objectForKey:@"weburl"];
                    self.pk0 = [articlesArr[i] objectForKey:@"pk"];
                }
            }
            //第一个新闻框
            for (int i = 0; i < [articlesArr count]; i++) {
                if ([arr[1] isEqualToString:[articlesArr[i] objectForKey:@"pk"]]) {
                    self.titleStr1 = [articlesArr[i] objectForKey:@"title"];
                    self.fromStr1 = [articlesArr[i] objectForKey:@"auther_name"];
                    self.weburl1 = [articlesArr[i] objectForKey:@"weburl"];
                    self.pk1 = [articlesArr[i] objectForKey:@"pk"];
                }
            }
            //第二个新闻框
            for (int i = 0; i < [articlesArr count]; i++) {
                if ([arr[2] isEqualToString:[articlesArr[i] objectForKey:@"pk"]]) {
                    self.titleStr2 = [articlesArr[i] objectForKey:@"title"];
                    self.fromStr2 = [articlesArr[i] objectForKey:@"auther_name"];
                    self.weburl2 = [articlesArr[i] objectForKey:@"weburl"];
                    self.pk2 = [articlesArr[i] objectForKey:@"pk"];
                }
            }
            //第三个新闻框
            for (int i = 0; i < [articlesArr count]; i++) {
                if ([arr[3] isEqualToString:[articlesArr[i] objectForKey:@"pk"]]) {
                    self.titleStr3 = [articlesArr[i] objectForKey:@"title"];
                    self.fromStr3 = [articlesArr[i] objectForKey:@"auther_name"];
                    self.weburl3 = [articlesArr[i] objectForKey:@"weburl"];
                    self.pk3 = [articlesArr[i] objectForKey:@"pk"];
                }
            }
            
            //第四个新闻框
            for (int i = 0; i < [articlesArr count]; i++) {
                if ([arr[4] isEqualToString:[articlesArr[i] objectForKey:@"pk"]]) {
                    self.titleStr4 = [articlesArr[i] objectForKey:@"title"];
                    self.fromStr4 = [articlesArr[i] objectForKey:@"auther_name"];
                    self.weburl4 = [articlesArr[i] objectForKey:@"weburl"];
                    self.pk4 = [articlesArr[i] objectForKey:@"pk"];
                }
            }
        } else if (arr.count == 6) {
            
            for (int i = 0; i < [articlesArr count]; i++) {
                if ([arr[0] isEqualToString:[articlesArr[i] objectForKey:@"pk"]]) {
                    self.titleImageStr = [[[articlesArr[i] objectForKey:@"media"] lastObject] objectForKey:@"url"];
                    self.imageTitleStr = [articlesArr[i] objectForKey:@"title"];
                    self.weburl0 = [articlesArr[i] objectForKey:@"weburl"];
                    self.pk0 = [articlesArr[i] objectForKey:@"pk"];
                }
            }
            //第一个新闻框
            for (int i = 0; i < [articlesArr count]; i++) {
                if ([arr[1] isEqualToString:[articlesArr[i] objectForKey:@"pk"]]) {
                    self.titleStr1 = [articlesArr[i] objectForKey:@"title"];
                    self.fromStr1 = [articlesArr[i] objectForKey:@"auther_name"];
                    self.weburl1 = [articlesArr[i] objectForKey:@"weburl"];
                    self.pk1 = [articlesArr[i] objectForKey:@"pk"];
                }
            }
            //第二个新闻框
            for (int i = 0; i < [articlesArr count]; i++) {
                if ([arr[2] isEqualToString:[articlesArr[i] objectForKey:@"pk"]]) {
                    self.titleStr2 = [articlesArr[i] objectForKey:@"title"];
                    self.fromStr2 = [articlesArr[i] objectForKey:@"auther_name"];
                    self.weburl2 = [articlesArr[i] objectForKey:@"weburl"];
                    self.pk2 = [articlesArr[i] objectForKey:@"pk"];
                }
            }
            //第三个新闻框
            for (int i = 0; i < [articlesArr count]; i++) {
                if ([arr[3] isEqualToString:[articlesArr[i] objectForKey:@"pk"]]) {
                    self.titleStr3 = [articlesArr[i] objectForKey:@"title"];
                    self.fromStr3 = [articlesArr[i] objectForKey:@"auther_name"];
                    self.weburl3 = [articlesArr[i] objectForKey:@"weburl"];
                    self.pk3 = [articlesArr[i] objectForKey:@"pk"];
                }
            }
            
            //第四个新闻框
            for (int i = 0; i < [articlesArr count]; i++) {
                if ([arr[4] isEqualToString:[articlesArr[i] objectForKey:@"pk"]]) {
                    self.titleStr4 = [articlesArr[i] objectForKey:@"title"];
                    self.fromStr4 = [articlesArr[i] objectForKey:@"auther_name"];
                    self.weburl4 = [articlesArr[i] objectForKey:@"weburl"];
                    self.pk4 = [articlesArr[i] objectForKey:@"pk"];
                }
            }
            //第五个新闻框
            for (int i = 0; i < [articlesArr count]; i++) {
                if ([arr[5] isEqualToString:[articlesArr[i] objectForKey:@"pk"]]) {
                    self.titleStr5 = [articlesArr[i] objectForKey:@"title"];
                    self.fromStr5 = [articlesArr[i] objectForKey:@"auther_name"];
                    self.weburl5 = [articlesArr[i] objectForKey:@"weburl"];
                    self.pk5 = [articlesArr[i] objectForKey:@"pk"];
                }
            }
        }
    }
    return self;
}

- (void)dealloc
{
    [_topImageStr release];
    [_titleImageStr release];
    [_imageTitleStr release];
    [_weburl0 release];
    [_pk0 release];
    [_titleStr1 release];
    [_fromStr1 release];
    [_weburl1 release];
    [_pk1 release];
    [_titleStr2 release];
    [_fromStr2 release];
    [_weburl2 release];
    [_pk2 release];
    [_titleStr3 release];
    [_fromStr3 release];
    [_weburl3 release];
    [_pk3 release];
    [_titleStr4 release];
    [_fromStr4 release];
    [_weburl4 release];
    [_pk4 release];
    [_titleStr5 release];
    [_fromStr5 release];
    [_weburl5 release];
    [_pk5 release];
    [super dealloc];
}

@end
